package br.com.ime.usp.cmep;

import android.content.Context;
import android.net.ConnectivityManager;

public class ConnectionUtils {

	private static Context ctx = null;
	private ConnectionUtils() { }
	
	public static void setContext(Context c) {
		if(ctx == null || c == null)
			ctx = c;
	}
	
	// verifica conexao com a Internet
    public static boolean isConnected() {    	
        try
        {
            ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); 
            return (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isAvailable() && cm.getActiveNetworkInfo().isConnected());  
        }
        catch (Exception e) {
            return false;
        }
    }
}
